package spark.network.protocol;

import spark.network.Util;

/**
 * If no specific data has to be sent as part of a response and its purpose is to merely acknowledge a packet
 * a GenericResponse can be sent. GenericResponse is unreliable per default but can be made reliable using
 * {@link Acknowledgement#makeReliable()}.
 */
public class Acknowledgement extends Response<Base> {
	public static final boolean RELIABLE_DEFAULT = false;
	public static final short TYPE = 0x01;
	private static final byte[] TYPE_BYTES = Util.makeBytes(TYPE);

	protected Acknowledgement() {
		super(RELIABLE_DEFAULT, TYPE_BYTES, Base.class);
	}

	public Acknowledgement(Base query) {
		super(RELIABLE_DEFAULT, TYPE_BYTES, query, Base.class);
	}

	public void makeReliable() {
		setReliable((byte)1);
	}

	public void makeUnreliable() {
		setReliable((byte)0);
	}

	public static Acknowledgement create(byte[] buffer, long receiveTime) {
		Acknowledgement packet = new Acknowledgement();
		packet.fill(buffer);
		packet.setTimeStampReceive(receiveTime);
		return packet;
	}
}